package com.zzyl.nursing.controller.member;

import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.nursing.dto.HealthDataDto;
import com.zzyl.nursing.dto.HealthDayDto;
import com.zzyl.nursing.dto.MemberDto;
import com.zzyl.nursing.service.MemUserService;
import com.zzyl.nursing.vo.ElderFamilyMyVo;
import com.zzyl.nursing.vo.ElderlyFamilyRelationVo;
import com.zzyl.nursing.vo.HealthDataVo;
import com.zzyl.nursing.vo.HealthDayVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 小程序端用户控制层
 *
 * @Author myl
 * @Date 2025/8/4 21:15
 */
@RestController
@RequestMapping("/member/user")
public class MemUserController extends BaseController {

    @Autowired
    private MemUserService memUserService;

    /**
     * 绑定家人
     *
     * @param dto
     * @return
     */
    @PostMapping("/add")
    @ApiOperation("绑定家人")
    public AjaxResult add(@RequestBody MemberDto dto) {
        memUserService.add(dto);
        return AjaxResult.success();
    }

    /**
     * 查看家人列表
     * @return
     */
    @GetMapping("/my")
    @ApiOperation("查看家人列表")
    public AjaxResult listAll(){
        List<ElderFamilyMyVo> list = memUserService.listAll();
        return success(list);
    }

    /**
     * 查询家人列表
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/list-by-page")
    @ApiOperation("查询家人列表")
    public AjaxResult listPage(@RequestParam Integer pageNum, @RequestParam Integer pageSize) {
        List<ElderlyFamilyRelationVo> list = memUserService.listPage(pageNum, pageSize);
        return success(list);
    }


    /**
     * 解绑
     * @param
     * @return
     */
    @DeleteMapping("/deleteById")
    public AjaxResult deleteByIds(@RequestParam Long id) {
        memUserService.deleteById(id);
        return success();
    }

    /**
     * 查看健康数据
     * @return
     */
    @ApiOperation("查看健康数据")
    @PostMapping("/QueryDevicePropertyStatus")
    public AjaxResult QueryDevicePropertyStatus(@RequestBody HealthDataDto dto){
        HealthDataVo healthDataVo = memUserService.QueryDevicePropertyStatus(dto);
        return success(healthDataVo);

    }

    /**
     * 按天统计查询指标数据
     * @param functionId
     * @param startTime
     * @param endTime
     * @param iotId
     * @return
     */
    @ApiOperation("按天统计查询指标数据")
    @GetMapping("/queryDeviceDataListByDay")
    public AjaxResult queryDeviceDataListByDay(@RequestParam String functionId,
                                               @RequestParam Long startTime,
                                               @RequestParam Long endTime,
                                               @RequestParam String iotId) {
        List<HealthDayVo> deviceDayVoList =memUserService.queryDeviceDataListByDay(functionId, startTime, endTime, iotId);
        return success(deviceDayVoList);
    }


    /**
     * 按周统计查询指标数据
     * @param dto
     * @return
     */

    @ApiOperation("按周统计查询指标数据")
    @GetMapping("/queryDeviceDataListByWeek")
    public AjaxResult queryDeviceDataListByWeek(HealthDayDto dto) {
        List<HealthDayVo> deviceDayVoList = memUserService.queryDeviceDataListByWeek(dto);
        return success(deviceDayVoList);
    }







}
